import {Component, OnInit, Input} from '@angular/core';
// import * as Highcharts from 'highcharts';

import {NavController, ActionSheetController, AlertController, NavParams,LoadingController, Events} from 'ionic-angular';
import {DomSanitizer} from '@angular/platform-browser';
import _ from "lodash";
import {Common} from "../../../../providers/common";
import {IrpQjtPersonService} from "./person.service";
import {IrpQjtpersonDetailPage} from "../personDetail/personDetail.component";

@Component({
  selector: "page-irp-panoramagram-person",
  templateUrl: 'person.html',
  providers: [IrpQjtPersonService]
})
export class IrpQjtPersonPage {
  title;
  groupIndex;
  datasList=[];
  isLoadMore = true;
  item;
  startDate = "2017-01-01";
  endDate = "2017-12-31";
  name = ["system", "chenyz", "zhaox", "lisi", "zhaowu", "chenyon", "libof", "zengy", "guqin", "anzhe", "shenhao", "xuchu", "yiran", "chengr", "yingy", "zhengz", "zhangz", "ruirong", "wuhui", "sundi", "feiy", "magong", "yuanye", "wucha", "jifeng", "yuanx"];

  constructor(public navCtrl: NavController,
              public alertCtrl: AlertController,
              public personService: IrpQjtPersonService,
              public common: Common,
              public navParams: NavParams,
              private loadingCtrl: LoadingController,
              private events: Events) {

    this.groupIndex = this.navParams.get("groupIndex");
    this.item = this.navParams.get("item");
    this.setDatasList();
  }

  setDatasList() {
    let loading = this.loadingCtrl.create({
      content: "加载中,请稍候...",
      // dismissOnPageChange: true
    });
    window['gfoa_loading'] = loading;
    loading.present();
    this.events.subscribe("loadingQJTDatas", () => {
      loading.dismiss();
      this.events.unsubscribe("loadingQJTDatas");
    });
    this.personService.getIRMSIRMOrgid(this.item.value).subscribe((data) => {
      console.log(data);
      if (data) {
        let x, obj;
        console.log(this.groupIndex)
        switch (this.groupIndex) {
          case 0:
            this.title="最新研究报告";
            this.personService.getIRMResearchReport(data[0].orgid, this.startDate, this.endDate).subscribe((data) => {
              if (data) {
                this.datasList = data;
              } else {
                this.isLoadMore = false;
              }
              loading.dismiss();
            });
            break;
          case 1:
            this.title="最新股票研究报告排名";
            this.personService.getIRMResearchReportRank(data[0].orgid, this.startDate, this.endDate).subscribe((data) => {
              if (data) {
                this.datasList = data;
              } else {
                this.isLoadMore = false;
              }
              this.isLoadMore = false;
              loading.dismiss();
            });
            break;
          case 2:
            this.title="最近出差";
            // this.personService.getIRMResearchReport(data,this.startDate,this.endDate).subscribe((data)=>{
            //   if(data){
            //     this.datasList=data;
            //   }
            // });
            this.isLoadMore = false;
            loading.dismiss();
            this.events.unsubscribe("loadingQJTDatas");
            break;
          case 3:
            this.title="最近策略推荐";
            this.personService.getIRMPolicyRecommend(data[0].orgid, this.startDate, this.endDate).subscribe((data) => {
              if (data) {
                this.datasList = data;
              } else {
                this.isLoadMore = false;
              }
              this.isLoadMore = false;
              loading.dismiss();
              this.events.unsubscribe("loadingQJTDatas");
            });
            break;
          case 4:
            this.title="最近金股推荐";
            this.personService.getIRMGoldStockRecommend(data[0].orgid, this.startDate, this.endDate).subscribe((data) => {
              if (data) {
                this.datasList = data;
              } else {
                this.isLoadMore = false;
              }
              this.isLoadMore = false;
              loading.dismiss();
              this.events.unsubscribe("loadingQJTDatas");
            });
            break;
          case 5:
            this.title="最新晨会股票推荐";
            this.personService.getIRMMorningStorck(data[0].orgid, this.startDate, this.endDate).subscribe((data) => {
              if (data) {
                this.datasList = data;
              } else {
                this.isLoadMore = false;
              }
              this.isLoadMore = false;
              loading.dismiss();
              this.events.unsubscribe("loadingQJTDatas");
            });
            break;
          case 6:
            this.title="最新股票池调整";
            this.personService.getIRMStockPoolAdjustment(data[0].orgid, this.startDate, this.endDate).subscribe((data) => {
              if (data) {
                this.datasList = data;
              } else {
                this.isLoadMore = false;
              }
              this.isLoadMore = false;
              loading.dismiss();
              this.events.unsubscribe("loadingQJTDatas");
            });
            break;
          default:
        }
      }else{
        this.isLoadMore = false;
        loading.dismiss();
      }
    })
    switch (this.groupIndex) {
      case 0:
        this.title = "最新研究报告";
        break;
      case 1:
        this.title = "最新股票研究报告排名";
        break;
      case 2:
        this.title = "最近出差";
        break;
      case 3:
        this.title = "最近策略推荐";
        break;
      case 4:
        this.title = "最近金股推荐";
        break;
      case 5:
        this.title = "最新晨会股票推荐";
        break;
      case 6:
        this.title = "最新股票池调整";
        break;

    }
  }

  goDetail(data) {
    this.navCtrl.push(IrpQjtpersonDetailPage, {item: data,groupIndex:this.groupIndex});
  }

}

